package com.hch.algorithm.recursion;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author HeCongHui
 * @date 2022/7/7 10:28
 */
public class SimpleRecursion {

    public static Boolean findKeyInKey(Box box) {
        List<Object> boxList = box.getItem();
        if (boxList != null) {
            for (Object boxChild : boxList) {
                if (boxChild instanceof Box) {
                    System.out.println(((Box) boxChild).getDesc());
                    findKeyInKey((Box) boxChild);
                } else if (boxChild instanceof Key) {
                    System.out.println("find the key");
                    return true;
                }
            }
        }
        return false;

    }

//    public int sum(int[] items) {
//if (items.)
//    }

    public static void main(String[] args) {
        Box boxA = new Box("A");
        Box boxB = new Box("B");
        Box boxC = new Box("C");
        Box boxD = new Box("D");
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(boxB);
        objects.add(boxC);
        boxA.setItem(objects);
        ArrayList<Object> objects1 = new ArrayList<>();
        objects1.add(boxD);
        boxC.setItem(objects1);
        ArrayList<Object> objectArrayList = new ArrayList<>();
        objectArrayList.add(new Key());
        boxD.setItem(objectArrayList);
        findKeyInKey(boxA);


    }
}

class Box {
    private List<Object> item;
    private String desc;

    public Box(String desc) {
        this.desc = desc;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public List<Object> getItem() {
        return item;
    }

    public void setItem(List<Object> item) {
        this.item = item;
    }
}

class Key {

}
